/****************************************************************************/
/***                                                                      ***/
/***   (C) 2012-2014 Dierk Ohlerich et al., all rights reserved.          ***/
/***                                                                      ***/
/***   Released under BSD 2 clause license, see LICENSE.TXT               ***/
/***                                                                      ***/
/****************************************************************************/

mtrl CubeShader 
{
  struct ia2vs
  {
    float3 pos : POSITION;
    float3 norm : NORMAL;
    float2 uv0 : TEXCOORD0;
  };

  struct vs2ps
  {
    min10float4 color : COLOR;
    min16float2 uv0 : TEXCOORD0;
  };

  cbuffer cbvs : vs(0) : register(0)
  {
    row_major float4x4 mat;
    float4 temp;
    float4 ldir;
  };

  // hlsl3
  
  vs hlsl3
  {
    void main(in ia2vs i,out vs2ps o,out float4 tpos : POSITION)
    {
      tpos = mul(mat,float4(i.pos,1));
      float l;
      l = max(dot(ldir.xyz,i.norm),0)+0.125;
      o.color = l;
      o.uv0 = i.uv0;
    }
  };

  ps hlsl3
  {
    SamplerState sam0 : register(s0);
    void main(in vs2ps i,out float4 r : COLOR)
    {
      r = i.color * tex2D(sam0,i.uv0);
    }
  };

  // hlsl5
  
  vs hlsl5
  {
    void main(in ia2vs i,out vs2ps o,out float4 tpos : SV_Position)
    {
      tpos = mul(mat,float4(i.pos,1));
      float l;
      l = max(dot(ldir.xyz,i.norm),0)+0.125;
      o.color = l;
      o.uv0 = i.uv0;
    }
  };

  ps hlsl5
  {
    SamplerState sam0 : register(s0);
    Texture2D tex0 : register(t0);
    void main(in vs2ps i,out float4 r : SV_Target)
    {
      r = i.color * tex0.Sample(sam0,i.uv0);
    }
  };

  // glsl1 
  
  vs glsl1 
  {
    void main()
    {
      gl_Position = mat*vec4(i_pos,1);
      float l;
      l = max(dot(ldir.xyz,i_norm),0.0)+0.125;
      o_color = vec4(l,l,l,l);
      o_uv0 = i_uv0;
    }
  };

  ps glsl1
  {
    uniform sampler2D sam0;
    void main()
    {
      gl_FragColor = i_color * texture2D(sam0,i_uv0);
    }
  };
} 

/****************************************************************************/
